$(function () {
    //time转换
    Date.prototype.format = function(format) {
        var o = {
            "M+": this.getMonth() + 1, // month
            "d+": this.getDate(), // day
            "h+": this.getHours(), // hour
            "m+": this.getMinutes(), // minute
            "s+": this.getSeconds(), // second
            "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
            "S": this.getMilliseconds()
            // millisecond
        };
        if(/(y+)/.test(format) || /(Y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for(var k in o) {
            if(new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    };


    $.ajaxSetup({
        //设置ajax请求结束后的执行动作  
        complete :
            function(XMLHttpRequest, textStatus) {
                // 通过XMLHttpRequest取得响应头，sessionstatus  
                var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
                if (sessionstatus == "TIMEOUT") {
                    var win = window;
                    while (win != win.top){
                        win = win.top;
                    }
                    layer.msg("登录超时，请重新登录",{icon:1},function () {
                        win.location.href= XMLHttpRequest.getResponseHeader("CONTEXTPATH");
                        // parent.topFrame.location.href = XMLHttpRequest.getResponseHeader("CONTEXTPATH");
                    });

                }
            }
    });
});


function setAjaxSetUp(jQueryObject) {
    if(typeof(jQueryObject)!="undefined") {
        jQueryObject.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete :
                function(XMLHttpRequest, textStatus) {
                    // 通过XMLHttpRequest取得响应头，sessionstatus  
                    var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
                    if (sessionstatus == "TIMEOUT") {
                        var win = window;
                        while (win != win.top){
                            win = win.top;
                        }
                        layer.msg("登录超时，请重新登录",{icon:1},function () {
                           win.location.href= XMLHttpRequest.getResponseHeader("CONTEXTPATH");
                            //  parent.topFrame.location.href = XMLHttpRequest.getResponseHeader("CONTEXTPATH");
                        });

                    }
                }
        });
    }
}


function iconAdd(imsg) {
    // "父页面："+parent.find("#iconMsg").text()
    $('#iconId').empty();
    $('#iconId').append('<i class="icon Hui-iconfont">'+imsg+'</i>');
}
//图标页面打开
$("#iconId").click(function () {
    // layer_show("图标","/webpage/common/include/icon_lists.jsp",'','420');
    layer.open({
        type: 2 //此处以iframe举例
        ,title: '图标'
        ,area: ['590px', '360px']
        ,shade: 0
        ,maxmin: true
        ,offset: [ //为了演示，随机坐标
            Math.random()*($(window).height()-300)
            ,Math.random()*($(window).width()-390)
        ]
        ,content: '/webpage/common/include/icon_lists.jsp'
        ,btn: ['关闭'] //只是为了演示
        ,yes: function(){
            layer.closeAll();
        }
        ,zIndex: layer.zIndex //重点1
        ,success: function(layero){
            layer.setTop(layero); //重点2
        }
    });
});
